﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace ZGEDrySaltery.Web.address
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int ADDRESS_ID=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(ADDRESS_ID);
				}
			}
		}
			
	private void ShowInfo(int ADDRESS_ID)
	{
		ZGEDrySaltery.BLL.address bll=new ZGEDrySaltery.BLL.address();
		ZGEDrySaltery.Model.address model=bll.GetModel(ADDRESS_ID);
		this.lblADDRESS_ID.Text=model.ADDRESS_ID.ToString();
		this.txtADDRESS.Text=model.ADDRESS;
		this.txtCREATE_USER_ID.Text=model.CREATE_USER_ID;
		this.txtCREATE_USER_NAME.Text=model.CREATE_USER_NAME;
		this.txtCREATE_TIME.Text=model.CREATE_TIME.ToString();
		this.txtSORT_INDEX.Text=model.SORT_INDEX.ToString();
		this.txtSTATUS.Text=model.STATUS;
		this.txtCOSTOMER.Text=model.COSTOMER;
		this.txtTEL.Text=model.TEL;
		this.txtREMARK.Text=model.REMARK;
		this.txtSEX.Text=model.SEX;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtADDRESS.Text.Trim().Length==0)
			{
				strErr+="ADDRESS不能为空！\\n";	
			}
			if(this.txtCREATE_USER_ID.Text.Trim().Length==0)
			{
				strErr+="CREATE_USER_ID不能为空！\\n";	
			}
			if(this.txtCREATE_USER_NAME.Text.Trim().Length==0)
			{
				strErr+="CREATE_USER_NAME不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtCREATE_TIME.Text))
			{
				strErr+="CREATE_TIME格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtSORT_INDEX.Text))
			{
				strErr+="SORT_INDEX格式错误！\\n";	
			}
			if(this.txtSTATUS.Text.Trim().Length==0)
			{
				strErr+="STATUS不能为空！\\n";	
			}
			if(this.txtCOSTOMER.Text.Trim().Length==0)
			{
				strErr+="COSTOMER不能为空！\\n";	
			}
			if(this.txtTEL.Text.Trim().Length==0)
			{
				strErr+="TEL不能为空！\\n";	
			}
			if(this.txtREMARK.Text.Trim().Length==0)
			{
				strErr+="REMARK不能为空！\\n";	
			}
			if(this.txtSEX.Text.Trim().Length==0)
			{
				strErr+="SEX不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int ADDRESS_ID=int.Parse(this.lblADDRESS_ID.Text);
			string ADDRESS=this.txtADDRESS.Text;
			string CREATE_USER_ID=this.txtCREATE_USER_ID.Text;
			string CREATE_USER_NAME=this.txtCREATE_USER_NAME.Text;
			DateTime CREATE_TIME=DateTime.Parse(this.txtCREATE_TIME.Text);
			int SORT_INDEX=int.Parse(this.txtSORT_INDEX.Text);
			string STATUS=this.txtSTATUS.Text;
			string COSTOMER=this.txtCOSTOMER.Text;
			string TEL=this.txtTEL.Text;
			string REMARK=this.txtREMARK.Text;
			string SEX=this.txtSEX.Text;


			ZGEDrySaltery.Model.address model=new ZGEDrySaltery.Model.address();
			model.ADDRESS_ID=ADDRESS_ID;
			model.ADDRESS=ADDRESS;
			model.CREATE_USER_ID=CREATE_USER_ID;
			model.CREATE_USER_NAME=CREATE_USER_NAME;
			model.CREATE_TIME=CREATE_TIME;
			model.SORT_INDEX=SORT_INDEX;
			model.STATUS=STATUS;
			model.COSTOMER=COSTOMER;
			model.TEL=TEL;
			model.REMARK=REMARK;
			model.SEX=SEX;

			ZGEDrySaltery.BLL.address bll=new ZGEDrySaltery.BLL.address();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
